import {HTTP} from "../../utils/http.js"
import {config} from "../../config.js";
import {FriendModel} from "../../models/friend.js";
import {ActModel} from "../../models/ActModel.js";
import Dialog from '../../miniprogram_npm/vant-weapp/dialog/dialog';
import { WorkModel } from "../../models/work.js";
const _WorkModel = new WorkModel();
var friend = new FriendModel();
var actBean =new ActModel();
var http = new HTTP();
const app = getApp();
var _self
Page({
  data: {
      userId:"",
      userName:"",
      wechatProfileUrl:"",
      mobile:"",
      percent:0,
      sumBPNumver:0,
      sumInviteNum:"",
      sumBePraised:0,
      sumBPLv:"",
      activePointLv:"",
      eduInfo:[],
      friendCount: "",
      address:"",
      degree:"",
      subject:"",
      positionTitle:"",
      geographicLocation:"",
      usrUserLables:[],
      workExpInfo:null,
      selfIntroduction:"",
      companyTitle:"",
      eduInfo:""
    },
  onHide:function(){
    // let pages = getCurrentPages();
    // pages[0].options={};
    app.globalData.isFromSharePage=true;
  },
  onShareAppMessage: function (options) {
    if (options.from === 'button') {
    
      if (options.target.dataset.available == 'shareMyCard') {
        console.log("shareMyCard 分支")
        return {
          desc: '' + _self.data.userName,
          path: 'pages/board/board?shareUserId=' + _self.data.userId,
          success: function (res) {
            wx.getShareInfo({
              shareTicket: res.shareTickets[0],
              success: function (res) {
                console.log("share", res)
              },
              fail: function (res) { console.log(res) },
              complete: function (res) { console.log(res) }
            });
          },
          fail: function () {

          }
        }
      }
    }

    

  },
  gotoMyProfile:function(){
    wx.reLaunch({
      url: '/pages/profile/profile?isFrom=sharePage'
    })
  },
  onLoad: function (options) {
    wx.showShareMenu({
      withShareTicket: true
    });
   
    _self = this;
    let userId = options.shareUserId;
    _self.setData({
      userId: options.shareUserId+""
    })
    wx.request({
      url: config.api_base_url +'/usr/sharedPersonInfo',
      method:"POST",
      data:{
        "sharedUserId": userId
      },
      success:function(res){
        console.log("zhaoyl",res);
        let errCode = res.data.errCode;
        let data ;
        if(errCode=='0000'){
          data = res.data.data[0];
          _self.setData({
            userName: data.userName,
            wechatProfileUrl: data.wechatProfileUrl,
            mobile: data.mobile,
            friendCount: data.friendCount,
            address: data.address,
            degree: data.Eucational_Background,
            geographicLocation: data.geographicLocation,
            subject: data.specializedSubject,
            positionTitle: data.title,
            startDate: data.startDate.substr(0, 4) + "级"
          })
          wx.setNavigationBarTitle({
            title: data.userName
          })
          let showInf = data.showInf;
          _self.setData({
            sumBPNumver: showInf.sumBPNumver,
            sumBePraised: showInf.sumBePraised,
            sumInviteNum: showInf.sumInviteNum,
            sumBPLv: showInf.sumBPLv,
            activePointLv: showInf.activePointLv,
            selfIntroduction: showInf.selfIntroduction,
            usrUserLables: showInf.usrUserLables
          })
          if (data.usrWorkExperience.length > 0) {
            let workInfo = data.usrWorkExperience[0];
            _self.setData({
              workExpInfo:workInfo,
              companyTitle: workInfo.work
            })
          }

          if (data.usrEduExperience.length > 0) {
            data.usrEduExperience.forEach(function(item,index){
              if (item.useForRealName=='1'){
                _self.setData({
                  eduInfo: item
                })
              }
            })
          }
        }
      }
    })
   
  }
})